<?php

namespace app\adminabc\model;

use think\Model;

class User extends Model {
	function getUser($map) {
		return db ( 'user' )->where ( $map )->order ( 'id desc' )->select ();
	}
	function addUser($data) {
		return db ( 'user' )->insertGetId ( $data );
	}
	function editUser($id, $data) {
		return db ( 'user' )->where ( array ([ 'id','=',$id ] ) )->update ( $data );
	}
	function getInfo($map) {
		$pre = config ( 'database.prefix' );
		return db ( 'user u' )->leftJoin ( "{$pre}role_user r", "u.id=r.user_id" )->where ( $map )->field ( "u.*,r.role_id" )->find ();
	}
	function delUser($id) {
		$log1 = db ( 'user' )->where ( array ([ 'id','=',$id ] ) )->delete ();
		$log2 = db ( 'role_user' )->where ( array ([ 'user_id','=',$id ] ) )->delete ();
		return $log1 + $log2;
	}
	function addRoleUser($data) {
		return db ( 'role_user' )->insertGetId ( $data );
	}
	function editRoleUser($id, $data) {
		return db ( 'role_user' )->where ( array ([ 'user_id','=',$id ] ) )->update ( $data );
	}
}

?>